//
//  UIBarButtonItemExtension.swift
//  weibopush
//
//  Created by 龚欣 on 15/6/29.
//  Copyright © 2015年 gong. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(imageName : String,imageName_highlighted : String?){
        let btn = UIButton()
        let imageName_h = imageName_highlighted ?? "\(imageName)_highlighted"
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: imageName_h), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        //调用uibarbuttonItem的initWithCustomView方法
        self.init(customView : btn)
    }
    
    convenience init(imageName : String,imageName_highlighted : String?,target: AnyObject?,ActionName : String?){
        let btn = UIButton()
        let imageName_h = imageName_highlighted ?? "\(imageName)_highlighted"
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: imageName_h), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        if ActionName != nil {
            btn.addTarget(target, action: Selector(ActionName!), forControlEvents: UIControlEvents.TouchUpInside)
        }
        //调用uibarbuttonItem的initWithCustomView方法
        self.init(customView : btn)
    
    }
}
